﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MachineBuildingSystem
{
    public partial class PageSizeSetForm : XtraForm
    {
        private int m_PageSize = 50;
        public int PageSize
        {
            get { return m_PageSize; }
        }
        public PageSizeSetForm()
        {
            InitializeComponent();
        }

        private void PageSizeSetForm_Load(object sender, EventArgs e)
        {
            int pageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"]);
            this.txtPageSize.Text = pageSize.ToString();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            m_PageSize = int.Parse(this.txtPageSize.Text.Trim());
            if (m_PageSize > 500)
            {
                MessageBox.Show(this, "每页最多显示500条数据！");
                return;
            }
            Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);    
            cfa.AppSettings.Settings["PageSize"].Value = m_PageSize.ToString();
            cfa.Save();
            ConfigurationManager.RefreshSection("appSettings");
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
